package com.lmh.controller;

import com.lmh.pojo.Demand;
import com.lmh.pojo.DemandApply;
import com.lmh.pojo.DemandVo;
import com.lmh.pojo.Userinfo;


import com.lmh.service.ApplyServie;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("/apply")
public class ApplyController {

    @Autowired
    private ApplyServie applyServie;

    @RequestMapping("/applyadd")
    @ResponseBody
    public List<Userinfo> applyadd(@RequestBody DemandVo demandVo, HttpSession session){
        System.out.println(demandVo.getDemandId());
        Userinfo userinfo=(Userinfo) session.getAttribute("userinfo");
        System.out.println(userinfo);
        DemandApply demandApply=new DemandApply();
        demandApply.setDemandId(demandVo.getDemandId());
        demandApply.setUserId(userinfo.getUserId());
        demandApply.setCreateTime(new Date());
        demandApply.setUpdateTime(new Date());
        int i=applyServie.applyadd(demandApply);
        List<Userinfo> demandApplies=applyServie.applyall(demandVo.getDemandId());
        return demandApplies;
    }
}
